// This source is subject to the Microsoft Public License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.IO;
using System.Windows.Forms;

namespace QuoteAdvantageEditor
{
	/// <summary>
	/// Summary description for FileNameDlg.
	/// </summary>
	public class FileNameDlg : System.Windows.Forms.Form
	{
      private System.Windows.Forms.Button btnCancel;
      private System.Windows.Forms.Button btnOK;
      private System.Windows.Forms.Label label1;
      private System.Windows.Forms.Label label2;
      private System.Windows.Forms.TextBox txtFileName;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

      public string FileName
      {
         get { return txtFileName.Text; }
      }

		public FileNameDlg()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
         this.btnCancel = new System.Windows.Forms.Button();
         this.btnOK = new System.Windows.Forms.Button();
         this.label1 = new System.Windows.Forms.Label();
         this.txtFileName = new System.Windows.Forms.TextBox();
         this.label2 = new System.Windows.Forms.Label();
         this.SuspendLayout();
         // 
         // btnCancel
         // 
         this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
         this.btnCancel.Location = new System.Drawing.Point(184, 104);
         this.btnCancel.Name = "btnCancel";
         this.btnCancel.Size = new System.Drawing.Size(80, 23);
         this.btnCancel.TabIndex = 4;
         this.btnCancel.Text = "Cancel";
         // 
         // btnOK
         // 
         this.btnOK.Location = new System.Drawing.Point(96, 104);
         this.btnOK.Name = "btnOK";
         this.btnOK.Size = new System.Drawing.Size(80, 23);
         this.btnOK.TabIndex = 3;
         this.btnOK.Text = "OK";
         this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
         // 
         // label1
         // 
         this.label1.Location = new System.Drawing.Point(8, 56);
         this.label1.Name = "label1";
         this.label1.Size = new System.Drawing.Size(88, 16);
         this.label1.TabIndex = 1;
         this.label1.Text = "Rule File Name:";
         // 
         // txtFileName
         // 
         this.txtFileName.Location = new System.Drawing.Point(96, 56);
         this.txtFileName.Name = "txtFileName";
         this.txtFileName.Size = new System.Drawing.Size(168, 21);
         this.txtFileName.TabIndex = 2;
         this.txtFileName.Text = "";
         // 
         // label2
         // 
         this.label2.Location = new System.Drawing.Point(8, 16);
         this.label2.Name = "label2";
         this.label2.Size = new System.Drawing.Size(264, 32);
         this.label2.TabIndex = 0;
         this.label2.Text = "Please specify the name that should be used for grouping the child products on th" +
            "is parent product";
         // 
         // FileNameDlg
         // 
         this.AcceptButton = this.btnOK;
         this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
         this.CancelButton = this.btnCancel;
         this.ClientSize = new System.Drawing.Size(280, 142);
         this.ControlBox = false;
         this.Controls.Add(this.label2);
         this.Controls.Add(this.txtFileName);
         this.Controls.Add(this.label1);
         this.Controls.Add(this.btnCancel);
         this.Controls.Add(this.btnOK);
         this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.MaximizeBox = false;
         this.MinimizeBox = false;
         this.Name = "FileNameDlg";
         this.ShowInTaskbar = false;
         this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
         this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
         this.Text = "Rule File Name";
         this.ResumeLayout(false);

      }
		#endregion

      private void btnOK_Click(object sender, System.EventArgs e)
      {
         bool  bResult = true;

         string strFileName = txtFileName.Text.Trim();

         if (strFileName == "")
         {
            MessageBox.Show(this, "Please enter a file name");
            bResult = false;
         }
         
         if (bResult)
         {
            if (Path.GetExtension(strFileName).ToLower() != ".xml")
            {
               strFileName = strFileName += ".xml";
            }

            txtFileName.Text = strFileName;
         }  

         if (bResult)
         {
            this.DialogResult = DialogResult.OK;
            this.Close();
         }
      }

	} // end class
}
